<template>
	<view class="restSet">
		<view class="setList">
			<view class="setItem dis">
				<view class="setL">社区实名</view>
				<view class="setR"><up-switch v-model="valueS" asyncChange @change="asyncChange"></up-switch></view>
			</view>
			<view class="setItem">
				<view class="itemT dis">
					<view class="setL">更改火帖阈值</view>
					<view class="setR dis" @click="open(1, data.threadHotThreshold)">
						<view class="">{{ data.threadHotThreshold }}</view>
						<view class="icon">
							<up-icon name="arrow-right" color="#969799" size="15"></up-icon>
						</view>
					</view>
				</view>
				<view class="itemB">24小时内，帖子评论人数达到阈值认定为火帖</view>
			</view>
			<view class="setItem dis">
				<view class="setL">跑腿-区域站长佣金分成</view>
				<view class="setR dis" @click="open(2, data.regionalStationmasterSharingRatio)">
					<view class="">{{ data.regionalStationmasterSharingRatio }}%</view>
					<view class="icon">
						<up-icon name="arrow-right" color="#969799" size="15"></up-icon>
					</view>
				</view>
			</view>
			<view class="setItem dis">
				<view class="setL">跑腿-站长佣金分成</view>
				<view class="setR dis" @click="open(3, data.stationmasterSharingRatio)">
					<view class="">{{ data.stationmasterSharingRatio }}%</view>
					<view class="icon">
						<up-icon name="arrow-right" color="#969799" size="15"></up-icon>
					</view>
				</view>
			</view>
			<view class="setItem dis">
				<view class="setL">跑腿-骑手佣金分成</view>
				<view class="setR dis" @click="open(4, data.recipientSharingRatio)">
					<view class="">{{ data.recipientSharingRatio }}%</view>
					<view class="icon">
						<up-icon name="arrow-right" color="#969799" size="15"></up-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
	<up-modal :title="title" :show="showModal" contentTextAlign="center" confirmButtonShape="circle">
		<view class="slot_content dis">
			<up-number-box v-model="value"></up-number-box>
		</view>
		<template #confirmButton>
			<view class="modalBut dis">
				<view class="custom_btn nodeBut" @click="okDel">取消</view>
				<view class="custom_btn" @click="okAdd">确定</view>
			</view>
		</template>
	</up-modal>
</template>

<script setup>
import { getSchoolList2, switchIsNeedIdentity, changeThresholdForHotThreads, changeRunErrandsCommissionSharing } from '@/config/api.js';
import { ref } from 'vue';
import { onShow, onLoad, onReachBottom } from '@dcloudio/uni-app';
const schoolId = ref(0);
onLoad((options) => {
	schoolId.value = options.schoolId;
	getData();
});
onShow(() => {});

const list = ref([]);
const data = ref({});
const valueS = ref(false);
const getData = async () => {
	const res = await getSchoolList2();
	// console.log(res);
	if (res.code == 0) {
		list.value = res.data.list;
		const item = list.value.find((ele) => ele.id == schoolId.value);
		console.log(item);
		data.value = item;
		if (item.isNeedIdentity == 1) {
			valueS.value = true;
		} else {
			valueS.value = false;
		}
	}
};

// 社区实名
const asyncChange = async (e) => {
	const dataS = {
		isNeedIdentity: e ? 1 : 0
	};
	const res = await switchIsNeedIdentity(2, dataS);
	if (res.code == 0) {
		valueS.value = e;
	}
};

// 弹窗
const showModal = ref(false);
const value = ref(0);
const title = ref('修改火贴阈值');
const type = ref(1);
const okDel = () => {
	value.value = 0;
	title.value = '修改火贴阈值';
	showModal.value = false;
};
const okAdd = async () => {
	let res = {};
	if (type.value == 1) {
		const datas = {
			threadHotThreshold: value.value
		};
		res = await changeThresholdForHotThreads(2, datas);
	} else if (type.value == 2) {
		const datas = {
			regionalStationmasterSharingRatio: value.value
		};
		res = await changeRunErrandsCommissionSharing(2, datas);
	} else if (type.value == 3) {
		const datas = {
			stationmasterSharingRatio: value.value
		};
		res = await changeRunErrandsCommissionSharing(2, datas);
	} else if (type.value == 4) {
		const datas = {
			recipientSharingRatio: value.value
		};
		res = await changeRunErrandsCommissionSharing(2, datas);
	}
	// console.log(res);
	if (res.code == 0) {
		okDel();
		getData();
	}
	uni.showToast({
		title: res.message,
		icon: 'none'
	});
};
const open = (num, val) => {
	if (num == 1) {
		title.value = '修改火贴阈值';
	} else {
		title.value = '修改佣金分成比例';
	}
	type.value = num;
	showModal.value = true;
	value.value = val;
};
</script>

<style lang="scss" scoped>
.restSet {
	.setList {
		.setItem {
			justify-content: space-between;
			align-items: center;
			padding: 25rpx 20rpx;
			border-bottom: 2rpx solid #ebedf0;
			background-color: #fff;
			font-size: 26rpx;
			.itemT {
				justify-content: space-between;
				align-items: center;
			}
			.itemB {
				line-height: 55rpx;
				font-size: 24rpx;
				color: #969799;
			}
			.setR {
				justify-content: space-between;
				align-items: center;
				color: #969799;
				.icon {
					// padding-top: 5rpx;
				}
			}
		}
	}
}
.slot_content {
	justify-content: center;
	width: 100%;
}
.modalBut {
	align-items: center;
	justify-content: space-around;
	width: 100%;
	.custom_btn {
		width: 40%;
		height: 70rpx;
		line-height: 70rpx;
		border-radius: 35rpx;
		text-align: center;
		color: #fff;
		background-color: #3391e6;
	}
	.nodeBut {
		color: #515151;
		background-color: #f0f0f0;
	}
}
</style>
<style>
page {
	background-color: #fff;
}
image {
	width: 100%;
	height: 100%;
}
.u-swipe-action-item__right__button__wrapper {
	background-color: #e63f31 !important;
}
.card {
	margin-bottom: 20rpx;
	background-color: #fff;
	border-radius: 15rpx;
}
</style>
